package com.prawn.ift.ctrlequipment.controller;

import com.prawn.ift.ctrlequipment.pojo.CtrlequipmentLog;
import com.prawn.ift.ctrlequipment.service.CtrlEquipmentLogService;

import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/23
 * @DESC： 控制设备操作记录管理
 */
@Controller
public class CtrlEquipmentLogController {

    @Autowired
    private CtrlEquipmentLogService ctrlEquipmentLogService;

    /**
     * 添加控制设备操作记录信息
     * @Param ctrlEquipmentLog
     * @return Result
     */
    @RequestMapping("/ctrlequipment/log/add")
    @ResponseBody
    public Result add(CtrlequipmentLog ctrlEquipmentLog) {

        ctrlEquipmentLog.setId(UUID.randomUUID().toString().replaceAll("-",""));
        ctrlEquipmentLog.setCreateDate(new Date());
        ctrlEquipmentLog.setUpdateDate(new Date());
        return ctrlEquipmentLogService.addCtrlEquipmentLog(ctrlEquipmentLog);
    }

    /**
     * 删除控制设备操作记录信息
     * @Param id
     * @return Result
     */
    @RequestMapping("/ctrlequipment/log/delete")
    @ResponseBody
    public Result delete(String id) {
        return ctrlEquipmentLogService.deleteCtrlEquipmentLog(id);
    }

    /**
     * 修改控制设备操作记录信息
     * @Param ctrlEquipmentLog
     * @return Result
     */
    @RequestMapping("/ctrlequipment/log/edit")
    @ResponseBody
    public Result edit(CtrlequipmentLog ctrlEquipmentLog) {
        ctrlEquipmentLog.setUpdateDate(new Date());
        ctrlEquipmentLog.setCreateDate(null);
        return ctrlEquipmentLogService.editCtrlEquipmentLog(ctrlEquipmentLog);
    }

    /**
     * 查询控制设备操作记录信息
     * @return CtrlequipmentLog
     */
    @RequestMapping("/ctrlequipment/log/{id}")
    @ResponseBody
    public CtrlequipmentLog get(@PathVariable String id) {
        return ctrlEquipmentLogService.getCtrlEquipmentLogById(id);
    }

    /**
     * 查询控制设备操作记录信息列表
     * @return Result
     */
    @RequestMapping("/ctrlequipment/log/list")
    @ResponseBody
    public Result getList() {
        return ctrlEquipmentLogService.getCtrlEquipmentLogList();
    }

    /**
     * 分页查询控制设备操作记录信息列表
     * @return Result
     */
    @RequestMapping("/ctrlequipment/log/page")
    @ResponseBody
    public Result getPage(int page,int limit) {
        return ctrlEquipmentLogService.getCtrlEquipmentLogPage(page,limit);
    }

}
